import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:scanner/common/assets.dart';
import 'package:scanner/config/wj_color.dart';
import 'package:scanner/widgets/future_detector.dart';



/// 通用widget
class WJCommonWidgets {
  ///字体Text
  static Text getText(
      String title, {
        double? fontSize,
        FontWeight fontWeight = FontWeight.normal,
        Color textColor = Colors.white,
        int? maxLines,
        double? height,
        TextDecoration? decoration = TextDecoration.none,
        List<Shadow>? shadows,
        TextAlign? textAlign,
      }) {
    return Text(
      title,
      style: TextStyle(
        fontSize: fontSize ?? 14.sp,
        color: textColor,
        height: height,
        decoration: decoration,
        shadows: shadows,
        decorationColor: textColor,
        fontWeight: fontWeight,
      ),
      maxLines: maxLines,
      textAlign: textAlign,
      overflow: TextOverflow.ellipsis,
    );
  }

  static Text getAppText(
      String text, {
        double? fontSize,
        FontWeight fontWeight = FontWeight.normal,
        TextAlign? textAlign,
        int? maxLines,
      }) {
    return Text(
      text,
      style: TextStyle(fontSize: fontSize ?? 14.sp, color: WJColor.appColor, fontWeight: fontWeight),
      textAlign: textAlign,
      maxLines: maxLines,
      overflow: TextOverflow.ellipsis,
    );
  }

  static Text getNormalText(
      String text, {
        double? fontSize,
        FontWeight fontWeight = FontWeight.w400,
        TextAlign? textAlign,
        int? maxLines,
      }) {
    return Text(
      text,
      style: TextStyle(fontSize: fontSize ?? 14.sp, color: WJColor.color2221, fontWeight: fontWeight),
      textAlign: textAlign,
      maxLines: maxLines,
      overflow: TextOverflow.ellipsis,
    );
  }

  static Text getWhiteText(
      String text, {
        double? fontSize,
        FontWeight fontWeight = FontWeight.normal,
        TextAlign? textAlign,
        int? maxLines,
      }) {
    return Text(
      text,
      style: TextStyle(fontSize: fontSize ?? 14.sp, color: Colors.white, fontWeight: fontWeight),
      textAlign: textAlign,
      maxLines: maxLines,
      overflow: TextOverflow.ellipsis,
    );
  }

  static Text getBlackText(
      String text, {
        double? fontSize,
        FontWeight fontWeight = FontWeight.bold,
        TextAlign? textAlign,
        int? maxLines,
      }) {
    return Text(
      text,
      style: TextStyle(fontSize: fontSize ?? 14.sp, color: Colors.black, fontWeight: fontWeight),
      textAlign: textAlign,
      maxLines: maxLines,
      overflow: TextOverflow.ellipsis,
    );
  }

  static Text getGrayText(
      String text, {
        double? fontSize,
        FontWeight fontWeight = FontWeight.normal,
        TextAlign? textAlign,
        int? maxLines,
      }) {
    return Text(
      text,
      style: TextStyle(fontSize: fontSize ?? 14.sp, color: WJColor.colorFF9F, fontWeight: fontWeight),
      textAlign: textAlign,
      maxLines: maxLines,
      overflow: TextOverflow.ellipsis,
    );
  }

  // // 设置项
  // static Widget setItem(
  //     String text,
  //     Function onTap, {
  //       bool? double,
  //       String? title,
  //       String? detailText,
  //
  //       // String? leftImage = Assets.assetsMkMineArrow,
  //       // String? subDetailText,
  //       // String subText = "",
  //       // Function? subTap,
  //       // String? subLeftImage = Assets.assetsMkMineArrow,
  //     }) {
  //   return WJCustomContainer(
  //     margin: EdgeInsets.only(top: 20.w),
  //     child: Column(
  //       crossAxisAlignment: CrossAxisAlignment.start,
  //       children: [
  //         if (title != null) WJCommonWidgets.getGrayText(title, fontWeight: FontWeight.bold, fontSize: 14.sp),
  //         WJCustomContainer(
  //           color: Colors.white,
  //           height: double == true ? 108.w : 64.w,
  //           width: 335.w,
  //           borderRadius: 15.w,
  //           padding: EdgeInsets.symmetric(horizontal: 15.w),
  //           child:
  //           double == true
  //               ? Column(
  //             children: [
  //               WJCustomContainer(
  //                 onTap: () {
  //                   onTap.call();
  //                 },
  //                 height: 54.w,
  //                 child: Row(
  //                   mainAxisAlignment: MainAxisAlignment.spaceBetween,
  //                   children: [
  //                     WJCommonWidgets.getText(
  //                       text,
  //                       fontWeight: FontWeight.bold,
  //                       textColor: WJColor.colorFF22,
  //                       fontSize: 16.sp,
  //                     ),
  //                     WJCustomContainer(
  //                       child: Row(
  //                         children: [
  //                           if (detailText != null)
  //                             WJCommonWidgets.getText(
  //                               detailText,
  //                               fontWeight: FontWeight.bold,
  //                               textColor: WJColor.colorFF22,
  //                               fontSize: 16.sp,
  //                             ),
  //                           MkImage(path: leftImage, width: 24.w, height: 24.w).paddingOnly(left: 2.w),
  //                         ],
  //                       ),
  //                     ),
  //                   ],
  //                 ),
  //               ),
  //               WJCustomContainer(
  //                 onTap: () {
  //                   subTap?.call();
  //                 },
  //                 height: 54.w,
  //                 child: Row(
  //                   mainAxisAlignment: MainAxisAlignment.spaceBetween,
  //                   children: [
  //                     WJCommonWidgets.getText(
  //                       subText,
  //                       fontWeight: FontWeight.bold,
  //                       textColor: WJColor.colorFF22,
  //                       fontSize: 16.sp,
  //                     ),
  //                     WJCustomContainer(
  //                       child: Row(
  //                         children: [
  //                           if (subDetailText != null)
  //                             WJCommonWidgets.getText(
  //                               subDetailText,
  //                               fontWeight: FontWeight.bold,
  //                               textColor: WJColor.colorFF22,
  //                               fontSize: 16.sp,
  //                             ),
  //                           MkImage(path: subLeftImage, width: 24.w, height: 24.w).paddingOnly(left: 2.w),
  //                         ],
  //                       ),
  //                     ),
  //                   ],
  //                 ),
  //               ),
  //             ],
  //           )
  //               : WJCustomContainer(
  //             onTap: () {
  //               onTap.call();
  //             },
  //             height: 54.w,
  //             child: Row(
  //               mainAxisAlignment: MainAxisAlignment.spaceBetween,
  //               children: [
  //                 WJCommonWidgets.getText(
  //                   text,
  //                   fontWeight: FontWeight.bold,
  //                   textColor: WJColor.colorFF22,
  //                   fontSize: 16.sp,
  //                 ),
  //                 WJCustomContainer(
  //                   child: Row(
  //                     children: [
  //                       if (detailText != null)
  //                         WJCommonWidgets.getText(
  //                           detailText,
  //                           fontWeight: FontWeight.bold,
  //                           textColor: WJColor.colorFF22,
  //                           fontSize: 16.sp,
  //                         ),
  //                       if (leftImage != null)
  //                         MkImage(path: leftImage, width: 24.w, height: 24.w).paddingOnly(left: 2.w),
  //                     ],
  //                   ),
  //                 ),
  //               ],
  //             ),
  //           ),
  //         ).paddingOnly(top: 10.w),
  //       ],
  //     ),
  //   );
  // }
  //
  // static Widget setItems(List<Map<String, dynamic>> items, {String? title}) {
  //   return WJCustomContainer(
  //     margin: EdgeInsets.only(top: 20.w),
  //     child: Column(
  //       crossAxisAlignment: CrossAxisAlignment.start,
  //       children: [
  //         if (title != null) WJCommonWidgets.getGrayText(title, fontWeight: FontWeight.bold, fontSize: 14.sp),
  //         WJCustomContainer(
  //           color: Colors.white,
  //           width: 335.w,
  //           borderRadius: 15.w,
  //           child: Column(
  //             children:
  //             items.map((item) {
  //               final String text = item['text'] ?? '';
  //               final String? detailText = item['detailText'];
  //               final String? leftImage = item['leftImage'];
  //               final String? rightImage = item['rightImage'];
  //               final Function? onTap = item['onTap'];
  //
  //               return WJCustomContainer(
  //                 onTap: () {
  //                   onTap?.call();
  //                 },
  //                 height: 64.w,
  //                 padding: EdgeInsets.symmetric(horizontal: 15.w),
  //                 child: Row(
  //                   mainAxisAlignment: MainAxisAlignment.spaceBetween,
  //                   children: [
  //                     Row(
  //                       children: [
  //                         if (leftImage != null)
  //                           MkImage(path: leftImage, width: 24.w, height: 24.w).paddingOnly(right: 10.w),
  //                         WJCommonWidgets.getText(
  //                           text,
  //                           fontWeight: FontWeight.bold,
  //                           textColor: WJColor.colorFF22,
  //                           fontSize: 16.sp,
  //                         ),
  //                       ],
  //                     ),
  //                     Row(
  //                       children: [
  //                         if (detailText != null)
  //                           WJCommonWidgets.getText(
  //                             detailText,
  //                             fontWeight: FontWeight.bold,
  //                             textColor: WJColor.colorFF22,
  //                             fontSize: 16.sp,
  //                           ),
  //                         if (rightImage != null)
  //                           MkImage(path: rightImage, width: 24.w, height: 24.w).paddingOnly(left: 10.w),
  //                       ],
  //                     ),
  //                   ],
  //                 ),
  //               );
  //             }).toList(),
  //           ),
  //         ).paddingOnly(top: 10.w),
  //       ],
  //     ),
  //   );
  // }

  ///主题色按钮
  static Widget commonAppButton(
      String btText, {
        double? width,
        double? height,
        Function? onTap,
        EdgeInsetsGeometry? margin,
        double? borderRadius,
        double? fontSize,
        Color? backgroundColor,
        Gradient? gradient,
        Color? textColor,
        String? iconPath,
        Color? iconColor,
        bool? active,
        double? iconWidth,
        double? iconHeight,
      }) {
    return WJFutureDetector(
      onTap: () async {
        if (onTap != null && (active ?? true)) {
          onTap();
        }
      },
      child: Container(
        width: width ?? 295.w,
        height: height ?? 60.w,
        margin: margin,
        alignment: Alignment.center,
        decoration: BoxDecoration(
          color: backgroundColor ?? ((active ?? true) ? WJColor.color2221 : WJColor.colorFF9F),
          borderRadius: BorderRadius.circular(borderRadius ?? 99.w),
          gradient: (active ?? true) ? gradient : null,
        ),
        child:
        iconPath != null
            ? Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Padding(
              padding: EdgeInsets.only(right: 7.w),
              child: Image.asset(
                iconPath,
                width: iconWidth ?? 24.w,
                height: iconHeight ?? 24.w,
                color: iconColor,
              ),
            ),
            Text(
              btText,
              style: TextStyle(
                color: textColor ?? (active == false ? Colors.white : WJColor.colorD3FD),
                fontSize: fontSize ?? 16.sp,
                fontWeight: FontWeight.w600,
              ),
            ),
          ],
        )
            : Text(
          btText,
          style: TextStyle(
            color: textColor ?? (active == false ? Colors.white : WJColor.colorD3FD),
            fontSize: fontSize ?? 16.sp,
            fontWeight: FontWeight.w600,
          ),
        ),
      ),
    );
  }

  ///主题色按钮
  static Widget commonGradientButton(
      String btText, {
        double? width,
        double? height,
        Function? onTap,
        EdgeInsetsGeometry? margin,
        double? borderRadius,
        double? fontSize,
        Color? backgroundColor,
        Gradient? gradient,
        Color? textColor,
        String? iconPath,
        Color? iconColor,
        bool? active,
      }) {
    return WJFutureDetector(
      onTap: () async {
        if (onTap != null && (active ?? true)) {
          onTap();
        }
      },
      child: Container(
        width: width ?? 343.w,
        height: height ?? 56.w,
        margin: margin,
        alignment: Alignment.center,
        decoration: BoxDecoration(
          // color: (active ?? true) ? ColorConfig.colorFF22 : ColorConfig.colorFF9F,
          borderRadius: BorderRadius.circular(borderRadius ?? 99.w),
          gradient: WJColor.vipBtnGradient,
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            if (iconPath != null)
              Padding(
                padding: EdgeInsets.only(right: 7.w),
                child: Image.asset(iconPath, width: 24.w, height: 24.w, color: iconColor),
              ),
            Text(
              btText,
              style: TextStyle(color: Colors.white, fontSize: fontSize ?? 16.sp, fontWeight: FontWeight.bold),
            ),
          ],
        ),
      ),
    );
  }

  //公共设置图片背景Container
  static Widget getBackImageContainer(
      String backImage, {
        double? width,
        double? height,
        Alignment? alignment,
        EdgeInsetsGeometry? padding,
        EdgeInsetsGeometry? margin,
        BorderRadiusGeometry? clipRadius, //是否需要裁剪整个container
        Widget? child,
      }) {
    var container = Container(
      width: width,
      height: height,
      alignment: alignment,
      padding: padding,
      margin: margin,
      decoration: BoxDecoration(image: DecorationImage(image: AssetImage(backImage), fit: BoxFit.cover)),
      child: child,
    );
    if (clipRadius != null) {
      return ClipRRect(borderRadius: clipRadius, child: container);
    }
    return container;
  }
}

class WJCustomContainer {
}
